package com.mars.foodserver.controller.app;

import com.mars.foodserver.controller.common.BaseController;
import com.mars.foodserver.entity.FoodNotes;
import com.mars.foodserver.response.result.R;
import com.mars.foodserver.service.IFoodNotesService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import lombok.AllArgsConstructor;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author wq
 * @since 2021-07-21
 */
@RestController
@RequestMapping("food/notes")
@AllArgsConstructor
public class FoodNotesController extends BaseController {

    final IFoodNotesService foodNotesService;

    /**
     * 创建笔记
     *
     * @param notes 笔记
     * @return R
     */
    @GetMapping("/createNotes")
    public R<Void> createNotes(String notes, String image) {
        foodNotesService.createNotes(getUserId(), notes, image);
        return R.success();
    }


    /**
     * 列表
     *
     * @return R<List < FoodNotes>>
     */
    @GetMapping("/list")
    public R<List<FoodNotes>> listNotes() {
        return R.success(foodNotesService.listNotes());
    }


    /**
     * 删除笔记
     *
     * @param id ID
     * @return R
     */
    @GetMapping("/delete")
    public R<Void> delete(Integer id) {
        foodNotesService.delete(id);
        return R.success();
    }

}
